package tokens

import (
	"github.com/astaxie/beego/context"
	"svntool/db/tables"
)

/**
 * token 工厂类
 */
var Token_model Token_interface
var Token_parse_model TokenParser_interface

//验证用户(基于tokens和token_parser)
func CkUser(ctx *context.Context) bool {
	uid, token := Token_parse_model.GetUid(ctx), Token_parse_model.GetToken(ctx)
	if uid == 0 || token == "" {
		return false
	}

	tokens := new(tables.Tokens).GetByUid(uid)

	if tokens.Token != token {
		return false
	}
	return true
}

func init() {
	Token_model = new(token)
	Token_parse_model = new(tokenParser)
}
